/*
 * 
 */
package org.demo.filemanager;

import java.awt.Frame;
import java.awt.event.FocusAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
import javax.media.opengl.Threading;

import org.boxlayout.gui.BoxLayoutEngine;

import sun.security.acl.WorldGroupImpl;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.FPSAnimator;


/**
 * TODO: Edit class comment
 * @author dodekane@gmail.com
 */
public class MainFrame extends Frame {

    GLCanvas canvas;
    
    public MainFrame(BoxLayoutEngine ble) {
        super("FileManager");
       //Threading.disableSingleThreading();        
        GLCapabilities caps = new GLCapabilities();
        caps.setDoubleBuffered( true );
        caps.setHardwareAccelerated( true );
        
        canvas = new GLCanvas(caps,null,GLContext.getCurrent(),null);
        ble.setCanvas(canvas);
        canvas.addGLEventListener(ble);

        canvas.addMouseListener(ble);
        canvas.addMouseMotionListener(ble);
        canvas.addKeyListener(ble);
        
        add(canvas);

        setSize(600, 600);
        final Animator animator = new FPSAnimator(canvas,120);
        animator.setRunAsFastAsPossible(false);
        //animator.setPrintExceptions(true);
        addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                new Thread(new Runnable() {

                    public void run() {
                        //animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        setVisible(true);
        
        addWindowListener( new WindowAdapter() {
          public void windowActivated( WindowEvent e ) {
            canvas.requestFocusInWindow(); } } );
        
        //requestFocus();
        //canvas.requestFocusInWindow();
       //animator.start();
       setFocusable(true);
       setFocusableWindowState(true);
    }

}
